<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class HomeController extends BaseController
{

	public function __construct()
	{
		parent::__construct();
	}
    public function index()
    {
        // 从monitor_alarm_history取出统计信息
        $result['alarming'] = DB::table('monitor_alarm')->where('status',0)->count();
        $result['canceled'] = DB::table('monitor_alarm_history')->where('status',3)->count();
    	return view(getThemeView('home.index'),compact('result'));
    }

    // 暂时从monitor_alarm和monitor_alarm_history表中取出报警点个数信息
    public function alarmnum() {
        // 取出monitor_alarm中的正在报警的测点数目
        // 暂时查询构造
        $result['alarming'] = DB::table('monitor_alarm')->where('status',0)->count();
        // 取出monitor_alarm_history中的已确认警报的数目
        $result['canceled'] = DB::table('monitor_alarm_history')->where('status',3)->count();
        return response()->json(array(
                'alarming' => $result['alarming'],
                'canceled' => $result['canceled']
            ));
    }

    //暂时留言提交位置
    public function note(Request $request) {
    	// $noteinfo = $request->input('noteinfo');
    	// dump($noteinfo);die;
    	// $data['title'] = $noteinfo['title'];
    	// $data['email'] = $noteinfo['email'];
    	// $data['content'] = $noteinfo['content'];
    	// dump($data);die;
        $note_all['title'] = $request->input('title');
        $note_all['content'] = $request->input('content');
        $note_all['email'] = $request->input('email');
        // dump($note_all);die;
        if (!empty($note_all['title'])) {
	        // 暂时查询构造器测试插入数据，改
	        $res = DB::table('message')->insert($note_all);
	        if ($res) {
	        	return response()->json(array(
	        			'res' => 1
	        		));
	        } else {
	        	return response()->json(array(
	        			'res' => 0
	        		));
	        }        	
        } else {
        	return  response()->json(array(
	        			'res' => 0
	        		));
        }

    }  
}
